﻿@using Ogdi.InteractiveSdk.Mvc
@inherits Ogdi.InteractiveSdk.Mvc.OgdiViewPage<Ogdi.InteractiveSdk.Mvc.Models.Comments.AgencyCommentViewModel>

@section TitleContent {

	<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

}
@section HeadContent {

	<style type="text/css">
		.canvas .sheet {border-left-width:5px;}
	</style>

}

 
  @Html.Partial("AgencyTabs", new Ogdi.InteractiveSdk.Mvc.Models.ViewData.AgencyTabsViewModel(Ogdi.InteractiveSdk.Mvc.Models.ViewData.AgencyTab.Comments)) 
 
 <script type="text/javascript">
     $(function() {
         var options = { altFormat: '@CommentsResources.AgencyComments.DateFormat', showAnim: '' };
         $("#From").datepicker(options);
         $("#To").datepicker(options);

         $("#From")[0].value = "@ViewData.Model.Filter.FromAsString";
         $("#To")[0].value = "@ViewData.Model.Filter.ToAsString";
     });

     function filter() {

         var fromFormat = $("#From").datepicker("option", "altFormat");
         var fromValue = $("#From").attr("value");
         var from = $.datepicker.parseDate(fromFormat, fromValue);

         var toValue = $("#To").attr("value");
         var to = $.datepicker.parseDate(fromFormat, toValue);

         $("#FromHidden")[0].value = fromValue;
         $("#ToHidden")[0].value = toValue;
         $("form").submit();
     }
     function DeleteComment(commentid,element) {
         var globVPath = '@this.ResolveUrl("~/")';
         var result;
         $.ajax(
            {
                type: "POST",
                async: false,
                url: globVPath + "Comments/DeleteComment/?id=" + commentid,
                data: result,
                dataType: "_default",
                success: function(data) {
                if (data == 'True') {
                        $('div#comment' + commentid).remove();
                    }
                }
            });
     }
     function showDiv(divId) {
         var divs = $("div#" + divId);
         if (divs.length > 0) {
             if (divs[0].style.display == 'none')
                 divs[0].style.display = 'inline';
             else
                 divs[0].style.display = 'none';
         }
     }

     function PostNewComment(rowKey,container,parentid,parenttype) {

         var subject = $("input#NewCommentSubject_" + rowKey)[0].value;
         var comment = $("textarea#NewComment_" + rowKey)[0].value;

         if (!subject || !comment) {
             $("#ReplyToCommentAlert_" + rowKey).text("@CommentsResources.AgencyComments.PleaseWriteAComment");
             return;
         }

         $.ajax({
             async: true,
             type: "POST",
             url: "/Comments/Reply",
             data:
             {
                 subject: subject,
                 comment: comment,
                 email: "",
                 type: "@CommentsResources.AgencyComments.GeneralCommentNoReplyRequired",
                 datasetId: parentid,
                 parentType: parenttype,
                 container: container,
                 origRowKey: rowKey
             },
             dataType: "json",
             success: function(data) {
                 if(data=="Replied"){
                     $("#ReplyToCommentAlert_" + rowKey).text("@CommentsResources.AgencyComments.PostedSuccessfully");
                     $("textarea#NewComment_" + rowKey).val("");
                 }else{
                     $("#ReplyToCommentAlert_" + rowKey).text("@CommentsResources.AgencyComments.AnErrorOccured");
                 }
             },
             error: function(XMLHttpRequest, textStatus, errorThrown) {
                 $("#ReplyToCommentAlert_" + rowKey).text("@CommentsResources.AgencyComments.AnErrorOccured");
             }
         });
     }

     function UpdateCommentStatus(rowKey, status, element) {
         $.ajax({
             async: true,
             type: "POST",
             url: "/Comments/UpdateStatus",
             data:
             {
                 rowKey: rowKey,
                 status: status
             },
             dataType: "json",
             success: function(data) {
             if (data.Show) {
                 $('div#statusValue' + rowKey).html(data.Status);
                 }
                 else {
                     $('div#comment' + rowKey).remove();
                 }
             },
             error: function(XMLHttpRequest, textStatus, errorThrown) {
                 alert(XMLHttpRequest.responseText);
             }
         });
     }
        
</script>

<div class="block">
	<div class="agency-comments">
		<div class="bar"> @CommentsResources.AgencyComments.ManageComments </div>

		<div class="form middle">
		@using (Html.BeginForm()){ 
			@CommentsResources.AgencyComments.Show                                      
			@Html.DropDownList("ShowStatus", Model.Statuses)
			@CommentsResources.AgencyComments.From
			<input id="From" maxlength="10" size="10" class="calendar" />
			@CommentsResources.AgencyComments.To
			<input id="To" maxlength="10" size="10" class="calendar" />
			@Html.Raw(Html.TextInputButton(this, CommentsResources.AgencyComments.Filter, "javascript:filter()"))
			@Html.Hidden("FromHidden")
			@Html.Hidden("ToHidden")
			} 
		</div>
    
        @foreach (var item in Model.Comments){ 
    
        <div class="commentItem comment" id="comment@item.RowKey">
        
			<div class="parameters">
				<div class="left" style="width:300px;">
					<div class="below">
						<div class="label">@item.ParentType</div>
						<div class="value"><a href="@this.Url.Content(item.ParentLink)">@item.ParentDisplay</a></div>
						<div class="clear"></div>
					</div>
					<div class="below">
						<div class="label"> @CommentsResources.AgencyComments.Author </div>
						<div class="value"> @Html.Partial("AuthorInfo", new Ogdi.InteractiveSdk.Mvc.Models.AuthorInfo(item.Author, item.Email)) </div>
						<div class="clear"></div>
					</div>
				</div>
				<div class="left" style="width:300px;">
					<div class="below">
						<div class="label"> @CommentsResources.AgencyComments.Type </div>
						<div class="value">@item.Type</div>
						<div class="clear"></div>
					</div>
					<div class="below">
						<div class="label"> @CommentsResources.AgencyComments.Posted </div>
						<div class="value">@item.Posted.ToString(Ogdi.InteractiveSdk.Mvc.Globals.ShortDateFormat)</div>
						<div class="clear"></div>
					</div>
				</div>
				<div class="left">
					<div class="below">
						<div class="label"> @CommentsResources.AgencyComments.Status </div>
						<div class="value" id="statusValue@item.RowKey">@item.Status</div>
						<div class="clear"></div>
					</div>
				</div>
				<div class="clear"></div>
			</div>
        
			<div class="message">
				<div class="name">@*<a href="<%=this.ResolveUrl(item.ParentLink) %>">*@@item.Subject@*</a>*@</div>
				<div class="description">@item.Body</div>
			</div>        
		
			<div class="controls middle admin-console">
				<span>[<a href="javascript:UpdateCommentStatus('@item.RowKey', 'Hidden', this)" class="delete"> @CommentsResources.AgencyComments.HideFromPublic @*<%= Html.TextButton(this, "delete", 0, null) %>*@</a>]</span>
				<span>[<a href="javascript:showDiv('Reply_' +'@item.RowKey')" class="reply"> @CommentsResources.AgencyComments.Reply @*<%= Html.TextButton(this, "reply", 0, null) %>*@</a>]</span>
				<span>[<a href="javascript:UpdateCommentStatus('@item.RowKey', 'Addresed', this)" class="mark-as-addressed"> @CommentsResources.AgencyComments.MarkAsAddressed @*<%= Html.TextButton(this, "mark-as-addressed", 0, null) %>*@</a>]</span>
				<span>[<a href="javascript:UpdateCommentStatus('@item.RowKey', 'NoActionRequired', this)" class="no-action-required"> @CommentsResources.AgencyComments.Archive @*<%= Html.TextButton(this, "no-action-required", 0, null) %>*@</a>]</span>
			</div>

			<div id="Reply_@item.RowKey" style="display: none; float:left;" class="form">
				<div class="bar"> @CommentsResources.AgencyComments.Reply </div>
				<div class="field">
					<div class="label"> @CommentsResources.AgencyComments.Subject </div>
					<div class=""><input id="NewCommentSubject_@item.RowKey" /></div>
					<div class="clear"></div>
				</div>
				<div class="field">
					<div class="label"> @CommentsResources.AgencyComments.Comment </div>
					<div class="">@Html.TextArea("NewComment_" + item.RowKey)</div>
					<div class="clear"></div>
				</div>
				<div class="field">
					<div class="label"></div>
					<div Id="ReplyToCommentAlert_@item.RowKey"></div>
					<div class="clear"></div>
				</div>
				<div class="buttons">
					@Html.Raw(Html.TextInputButton(this, CommentsResources.AgencyComments.PostComment, "javascript:PostNewComment('" + item.RowKey + "', '" + item.ParentContainer + "', '" + item.ParentName + "', '" + item.ParentType + "')"))
				</div>
			</div>
			<div class="clear"></div>
			
        </div>
  
	   }

    </div>
</div>




